import request from '@/axios/userRequest'

const store = {
  namespaced: true,
  state: {
    isLogin: false,
    LiveCodeInDomainList: null,
    noticeRadio: [
      { text: '邮箱', value:'1', imgBgClass: 'success-box', imgName: 'email_icon' },
      { text: '短信', value:'2', imgBgClass: 'warning-box', imgName: 'message_icon' },
      { text: '手机', value:'3', imgBgClass: 'red-box', imgName: 'phone_icon' },
      { text: '钉钉', value:'5', imgBgClass: 'primary-box', imgName: 'dingding_icon' },
      { text: '企业微信', value:'7', imgBgClass: 'primary-box', imgName: 'enterprise_wechat_icon' },
      { text: '飞书', value:'8', imgBgClass: '', imgName: 'feishu_icon', radioClass: 'feishu-radio' },
    ],
    httpRequestList: [],
    token: 'b134d9e397e2695dac79a55da877127b4cc38d54',
    jcApiUrl: 'http://api.user.urlzt.com/api',
  },
  mutations: {
    changeStoreState (state,data){
      state[data[0]] = data[1]
    },
    logout (state) {
      request.post('/logout').then(() => {
        location.replace('/login')
        localStorage.removeItem('userCenter_token')
        state.commit('changeStoreState', ['isLogin',false])
      }).catch(err => {})
    },
    addHttpRequestList(state, payload) {
      if (payload == 0) {
        state.httpRequestList.forEach(item => item('suspend'))// 添加标识，中断请求
        state.httpRequestList = []
      } else {
        state.httpRequestList.push(payload)
      }
    }
  },
  actions: {
    // 移除请求
    async removeHttpRequestList(ctx) {
      ctx.commit('addHttpRequestList', 0)
    }
  }
}

export default store
